﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;

namespace Milan.Windows
{
	public class shell32
	{
		private const int MAX_PATH = 260;

		[Flags]
		public enum SHGetFileInfoConstants : int
		{
			SHGFI_ICON = 0x100,					// get icon 
			SHGFI_DISPLAYNAME = 0x200,			// get display name 
			SHGFI_TYPENAME = 0x400,				// get type name 
			SHGFI_ATTRIBUTES = 0x800,			// get attributes 
			SHGFI_ICONLOCATION = 0x1000,		// get icon location 
			SHGFI_EXETYPE = 0x2000,				// return exe type 
			SHGFI_SYSICONINDEX = 0x4000,		// get system icon index 
			SHGFI_LINKOVERLAY = 0x8000,			// put a link overlay on icon 
			SHGFI_SELECTED = 0x10000,			// show icon in selected state 
			SHGFI_ATTR_SPECIFIED = 0x20000,		// get only specified attributes 
			SHGFI_LARGEICON = 0x0,				// get large icon 
			SHGFI_SMALLICON = 0x1,				// get small icon 
			SHGFI_OPENICON = 0x2,				// get open icon 
			SHGFI_SHELLICONSIZE = 0x4,			// get shell size icon 
			//SHGFI_PIDL = 0x8,					// pszPath is a pidl 
			SHGFI_USEFILEATTRIBUTES = 0x10,		// use passed dwFileAttribute 
			SHGFI_ADDOVERLAYS = 0x000000020,	// apply the appropriate overlays
			SHGFI_OVERLAYINDEX = 0x000000040	// Get the index of the overlay
		}

		[StructLayout(LayoutKind.Sequential)]
		public struct SHFILEINFO
		{
			public IntPtr hIcon;
			public int iIcon;
			public int dwAttributes;
			[MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_PATH)]
			public string szDisplayName;
			[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)]
			public string szTypeName;
		}

		[DllImport("shell32")]
		public static extern int SHGetFileInfo( string pszPath, int dwFileAttributes, ref SHFILEINFO psfi, uint cbFileInfo, uint uFlags);

		[DllImport("Shell32", CharSet = CharSet.Auto)]
		internal extern static int ExtractIconEx( [MarshalAs(UnmanagedType.LPTStr)] string lpszFile, int nIconIndex, IntPtr[] phIconLarge, IntPtr[] phIconSmall, int nIcons);
	}
}
